package cn.tedu.blog.server.controller.api;



import cn.tedu.blog.server.pojo.dto.PageDTO;
import cn.tedu.blog.server.pojo.entity.ArticleItem;
import cn.tedu.blog.server.service.ISearchService;
import cn.tedu.blog.server.utils.JsonPage;
import cn.tedu.blog.server.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/search")
@Api(tags="搜索模块")
public class SearchController {
    @Autowired
    private ISearchService searchService;

    @PostMapping
    @ApiOperation("根据用户输入关键字分页查询文章")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "搜索关键字",name = "keyword",dataType = "string"),
            @ApiImplicitParam(value = "页码",name = "page",dataType = "int"),
            @ApiImplicitParam(value = "每页条数",name = "pageSize",dataType = "int")
    })
    public JsonResult<JsonPage<ArticleItem>> searchByKeyword(@RequestBody PageDTO pageDTO){
        log.debug("接收到得数据：{},{},{}",pageDTO.getKeyword(),pageDTO.getPage(),pageDTO.getPageSize());
        JsonPage<ArticleItem> list=searchService.search(pageDTO.getKeyword(),pageDTO.getPage(),pageDTO.getPageSize());
        log.debug("Es查询出的结果：{}",list.toString());

        return JsonResult.ok(list);
    }


}
